package cn.wolfcode.crm.domain;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 客户跟进历史
 */
@Setter
@Getter
public class CustomerTraceHistory {
    private Long id;

    //跟进时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date traceTime;
    //跟进内容
    private String traceDetails;
    //跟进方式
    private SystemDictionaryItem traceType;
    //跟进结果
    private Integer traceResult;
    //备注
    private String remark;
    //客户
    private Customer customer;
    //录入人
    private Employee inputUser;
    //录入时间
    private Date inputTime;
    //跟进类型
    private Integer type;

    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", this.id);
        map.put("traceTime", this.traceTime);
        map.put("traceDetails", this.traceDetails);
        map.put("traceResult", this.traceResult);
        map.put("remark", this.remark);
        map.put("inputTime", this.inputTime);
        map.put("type", this.type);
        if (this.customer != null) {
            map.put("customerName", this.customer.getName());
            map.put("customerId", this.customer.getId());
        }
        if (this.inputUser != null) {
            map.put("inputUserName", this.inputUser.getName());
            map.put("inputUserId", this.inputUser.getId());
        }
        if (this.traceType != null) {
            map.put("traceTypeId", this.traceType.getId());
            map.put("traceTypeTitle", this.traceType.getTitle());
        }

        return JSON.toJSONString(map);
    }

}